home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / TableModelEvent.java < prev    next >
Text File  |  1998-06-30  |  6KB  |  167 lines

  1. /*
  2.  * @(#)TableModelEvent.java    1.10 98/02/02
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20.  
  21. package com.sun.java.swing.event;
  22.  
  23. import java.util.EventObject;
  24. import com.sun.java.swing.table.*;
  25.  
  26. /**
  27.  * TableModelEvent is used to notify listeners that a table model
  28.  * has changed. The model event describes changes to a TableModel 
  29.  * and all references to rows and columns are in the co-ordinate 
  30.  * system of the model. 
  31.  * Depending on the parameters used in the constructors, the TableModelevent
  32.  * can be used to specify the following types of changes: <p>
  33.  *
  34.  * <pre>
  35.  * TableModelEvent(source);              //  The data, ie. all rows changed 
  36.  * TableModelEvent(source, HEADER_ROW);  //  Structure change, reallcoate TableColumns
  37.  * TableModelEvent(source, 1);           //  Row 1 changed
  38.  * TableModelEvent(source, 3, 6);        //  Rows 3 to 6 inclusive changed
  39.  * TableModelEvent(source, 2, 2, 6);     //  Cell at (2, 6) changed
  40.  * TableModelEvent(source, 3, 6, ALL_COLUMNS, INSERT); // Rows (3, 6) were inserted
  41.  * TableModelEvent(source, 3, 6, ALL_COLUMNS, DELETE); // Rows (3, 6) were deleted
  42.  * </pre>
  43.  *
  44.  * It is possible to use other combinations of the parameters, not all of them 
  45.  * are meaningful. By subclassing, you can add other information, for example: 
  46.  * whether the event WILL happen or DID happen. This makes the specification 
  47.  * of rows in DELETE events more useful but has not been included in 
  48.  * the swing package as the JTable only needs post-event notification. 
  49.  * <p>
  50.  * Warning: serialized objects of this class will not be compatible with
  51.  * future swing releases.  The current serialization support is appropriate
  52.  * for short term storage or RMI between Swing1.0 applications.  It will
  53.  * not be possible to load serialized Swing1.0 objects with future releases
  54.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  55.  * baseline for the serialized form of Swing objects.
  56.  *
  57.  * @version 1.10 02/02/98
  58.  * @author Alan Chung
  59.  * @author Philip Milne
  60.  * @see TableModel
  61.  */
  62. public class TableModelEvent extends java.util.EventObject
  63. {
  64.     public static final int INSERT =  1;
  65.     public static final int UPDATE =  0;
  66.     public static final int DELETE = -1;
  67.     
  68.     public static final int HEADER_ROW = -1;
  69.  
  70.     public static final int ALL_COLUMNS = -1;
  71.     
  72. //
  73. //  Instance Variables
  74. //
  75.  
  76.     protected int       type;
  77.     protected int    firstRow;
  78.     protected int    lastRow;
  79.     protected int    column;
  80.  
  81. //
  82. // Constructors
  83. //
  84.  
  85.     /** 
  86.      *  All row data in the table has changed, listeners should discard any state 
  87.      *  that was based on the rows and requery the TableModel to get the new 
  88.      *  row count and all the appropriate values. 
  89.      *  The JTable will repaint the entire visible region on recieving 
  90.      *  this event, querying the model for the cell values that are visble. 
  91.      *  The structure of the table ie, the column names, types and order 
  92.      *  have not changed.  
  93.      */
  94.     public TableModelEvent(TableModel source) {
  95.         // Use Integer.MAX_VALUE instead of getRowCount() in case rows were deleted. 
  96.     this(source, 0, Integer.MAX_VALUE, ALL_COLUMNS, UPDATE);
  97.     }
  98.     
  99.     /**
  100.      *  This row of data has been updated. 
  101.      *  To denote the arrival of a completely new table with a different structure 
  102.      *  use <code>HEADER_ROW</code> as the value for the <I>row</I>. 
  103.      *  When the JTable recieves this event and its <I>autoCreateColumnsFromModel</I> 
  104.      *  flag is set it discards any TableColumns that it had and reallocates 
  105.      *  default ones in the order they appear in the model. This is the 
  106.      *  same as calling <code>setModel(TableModel)</code> on the JTable. 
  107.      */
  108.     public TableModelEvent(TableModel source, int row) {
  109.     this(source, row, row, ALL_COLUMNS, UPDATE);
  110.     }
  111.     
  112.     /**
  113.      *  The data in rows [<I>firstRow</I>, <I>lastRow</I>] have been updated. 
  114.      */
  115.     public TableModelEvent(TableModel source, int firstRow, int lastRow) {
  116.     this(source, firstRow, lastRow, ALL_COLUMNS, UPDATE);
  117.     }
  118.     
  119.     /**
  120.      *  The cells in column <I>column</I> in the range 
  121.      *  [<I>firstRow</I>, <I>lastRow</I>] have been updated. 
  122.      */
  123.     public TableModelEvent(TableModel source, int firstRow, int lastRow, int column) {
  124.     this(source, firstRow, lastRow, column, UPDATE);
  125.     }
  126.     
  127.     /**
  128.      *  The cells from (firstRow, column) to (lastRow, column) have been changed. 
  129.      *  The <I>column</I> refers to the column index of the cell in the model's 
  130.      *  co-ordinate system. When <I>column</I> is ALL_COLUMNS, all cells in the 
  131.      *  specified range of rows are considered changed. 
  132.      *  <p>
  133.      *  The <I>type</I> should be one of: INSERT, UPDATE and DELETE. 
  134.      */
  135.     public TableModelEvent(TableModel source, int firstRow, int lastRow, int column, int type) {
  136.     super(source);
  137.     this.firstRow = firstRow;
  138.     this.lastRow = lastRow;
  139.     this.column = column;
  140.     this.type = type;
  141.     }
  142.  
  143. //
  144. // Querying Methods
  145. //
  146.  
  147.    /** Returns the first row that changed.  HEADER_ROW means the meta data, 
  148.      * ie. names, types and order of the columns. 
  149.      */
  150.     public int getFirstRow() { return firstRow; };
  151.  
  152.     /** Returns the last row that changed. */
  153.     public int getLastRow() { return lastRow; };
  154.     
  155.     /**
  156.      *  Returns the column for the event.  If the return
  157.      *  value is ALL_COLUMNS; it means every column in the specified
  158.      *  rows changed.
  159.      */
  160.     public int getColumn() { return column; }; 
  161.     
  162.     /**
  163.      *  Returns the type of event - one of: INSERT, UPDATE and DELETE.
  164.      */
  165.     public int getType() { return type; }
  166. }
  167.